﻿#include<iostream>
#include "ClientSocket.h"
using namespace std;
CClientSocket::CClientSocket()
{
}

CClientSocket::~CClientSocket()
{
}
//重写socket的回调
void CClientSocket::OnClose(int nErrorCode){
		CSocket::OnClose(nErrorCode);
		cout << "服务器断开连接！" << endl;
	}
void CClientSocket::test()
{
	cout << "test" << endl;
}
//接收服务器消息的回调函数
void CClientSocket::OnReceive(int nErrorCode)
{
	// TODO:  在此添加专用代码和/或调用基类
	char* pData = NULL;
	pData = new char[1024];
	memset(pData, 0, sizeof(char)* 1024);
	UCHAR leng = 0;
	leng = Receive(pData, 1024, 0);
	cout << pData << endl;
	delete pData;
	pData = NULL;
	CSocket::OnReceive(nErrorCode);
}

//向服务器发送消息
bool CClientSocket::SendMSG(LPSTR lpBuff, int nlen)
{
	//生成协议头
	if (Send(lpBuff, nlen) == SOCKET_ERROR)
	{
		return FALSE;
	}
	return  TRUE;
}
